import unittest
from page.reception.login_page import LoginPage
from common.functions import browser_operation
from common.base import By
from page.reception.usercenter_page import UserCenterPage


# 创建订单类
class OrderCase(unittest.TestCase):
    """订单相关测试"""

    @classmethod
    def setUpClass(cls) -> None:
        # 调用functions打开浏览器
        driver = browser_operation()
        cls.login = LoginPage(driver)
        cls.login.get_website(cls.login.login_url)
        cls.center = UserCenterPage(driver)
        driver.implicitly_wait(5)

    def test_order_01(self):
        """测试商品支付生成的订单编号与订单列表里显示的是否一致"""
        # 输入账号密码
        self.login.input_username('zhang')
        self.login.input_password('123456')
        # 登录
        self.login.btn_login()
        # 点击首页按钮进入首页
        self.login.click((By.LINK_TEXT, '首页'))
        # 点击智能相机进入商品页面
        self.login.click((By.XPATH, '/html/body/div[6]/div/div/div[2]/div[2]/div/a[1]/div[1]/img'))
        # 点击立即购买
        self.login.click((By.XPATH, '//*[@id="ECS_FORMBUY"]/ul/li[7]/table/tbody/tr/td[1]/a/img'))
        # 点击去结算
        self.login.click((By.XPATH, '/html/body/div[6]/div[1]/table/tbody/tr/td[2]/a/img'))
        # 选择支付方式为余额支付
        self.login.click((By.XPATH, '//*[@id="paymentTable"]/tbody/tr[2]/td[1]/input'))
        # 点击提交订单
        self.login.click((By.XPATH, '//*[@id="theForm"]/div[15]/div[2]/input[1]'))
        # 订单提交成功,获取订单号
        number1 = self.login.get_element_text((By.XPATH, '/html/body/div[6]/div/h6/font'))
        # 点击用户中心
        self.center.user_center()
        # 点击我的订单
        self.center.my_order()
        # 获取订单号
        number2 = self.center.read_order_id()
        # 断言两个页面的订单号相同
        self.assertEqual(number1, number2)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.login.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
